//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Main.h"
#include "Pass.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TPassForm *PassForm;
//---------------------------------------------------------------------------
__fastcall TPassForm::TPassForm(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TPassForm::FormClose(TObject *Sender, TCloseAction &Action)
{
    MotorControl->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TPassForm::OKBtClick(TObject *Sender)
{
	MotorControl->pPassADO->First();
	String str;
	if (MotorControl->s_AdjEnable == true)
	{
		str = MotorControl->pPassADO->FieldValues["Adj"];
		if (str == PasswordEd->Text)
		{
			MotorControl->SpeedCtrl->Enabled = true;
		}
		else
		{
			ShowMessage("Password incorrect!");
        }
	}
	else
	{
		str = MotorControl->pPassADO->FieldValues["Setting"];
		if (str == PasswordEd->Text)
		{
			MotorControl->PageCtrl->ActivePageIndex = 1;
		}
		else
		{
			MotorControl->PageCtrl->ActivePageIndex = 0;
			ShowMessage("Password incorrect!");
        }
	}
	PassForm->Close();
}
//---------------------------------------------------------------------------
void __fastcall TPassForm::FormShow(TObject *Sender)
{
	PasswordEd->Text = "";
}
//---------------------------------------------------------------------------
void __fastcall TPassForm::CancelBtClick(TObject *Sender)
{
	if (MotorControl->s_AdjEnable == false)
	{
		MotorControl->PageCtrl->ActivePageIndex = 0;
	}
	PassForm->Close();
}
//---------------------------------------------------------------------------
void __fastcall TPassForm::PasswordEdKeyPress(TObject *Sender, wchar_t &Key)
{
	if ('\r' == Key)
	{
		OKBtClick(Sender);
	}
}
//---------------------------------------------------------------------------
